package com.ruoyi.campus.controller;

import com.ruoyi.campus.domain.Campusdistribution;
import com.ruoyi.campus.domain.vo.CampusdistributionVO;
import com.ruoyi.campus.service.ICampusService;
import com.ruoyi.campus.service.ICampusdistributionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 校区分销配置Controller
 * 
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/campus/campusdistribution")
public class CampusdistributionController extends BaseController
{
    @Autowired
    private ICampusdistributionService campusdistributionService;

    @Autowired
    private ICampusService campusService;

    /**
     * 查询校区分销配置列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:list')")
    @GetMapping("/list")
    public TableDataInfo list(CampusdistributionVO campusdistributionvo)
    {
        startPage();
        List<CampusdistributionVO> list = campusdistributionService.selectCampusdistributionList(campusdistributionvo);
        return getDataTable(list);
    }



    // /**
    //  * 查询校区分销配置列表
    //  */
    // @PreAuthorize("@ss.hasPermi('campus:campusdistribution:list')")
    // @GetMapping("/list")
    // public TableDataInfo list(Campusdistribution campusdistribution)
    // {
    //     startPage();
    //     List<Campusdistribution> list = campusdistributionService.selectCampusdistributionList(campusdistribution);
    //     return getDataTable(list);
    // }


    /**
     * 导出校区分销配置列表
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:export')")
    @Log(title = "校区分销配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampusdistributionVO campusdistributionvo)
    {
        List<CampusdistributionVO> list = campusdistributionService.selectCampusdistributionList(campusdistributionvo);
        ExcelUtil<CampusdistributionVO> util = new ExcelUtil<CampusdistributionVO>(CampusdistributionVO.class);
        util.exportExcel(response, list, "校区分销配置数据");
    }

    /**
     * 获取校区分销配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:query')")
    @GetMapping(value = "/{distributionId}")
    public AjaxResult getInfo(@PathVariable("distributionId") Integer distributionId)
    {
        return success(campusdistributionService.selectCampusdistributionByDistributionId(distributionId));
    }

    /**
     * 新增校区分销配置
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:add')")
    @Log(title = "校区分销配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Campusdistribution campusdistribution)
    {
        return toAjax(campusdistributionService.insertCampusdistribution(campusdistribution));
    }

    /**
     * 修改校区分销配置
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:edit')")
    @Log(title = "校区分销配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Campusdistribution campusdistribution)
    {
        return toAjax(campusdistributionService.updateCampusdistribution(campusdistribution));
    }

    /**
     * 删除校区分销配置
     */
    @PreAuthorize("@ss.hasPermi('campus:campusdistribution:remove')")
    @Log(title = "校区分销配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{distributionIds}")
    public AjaxResult remove(@PathVariable Integer[] distributionIds)
    {
        return toAjax(campusdistributionService.deleteCampusdistributionByDistributionIds(distributionIds));
    }
}
